package net.guerlab.smart.uploader.api.feign;

import net.guerlab.smart.uploader.api.feign.factory.FeignUploadApiFallbackFactory;
import net.guerlab.spring.upload.entity.FileInfo;
import net.guerlab.web.result.Result;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestPart;

/**
 * 上传服务接口
 *
 * @author guer
 */
@FeignClient(name = "uploader", fallbackFactory = FeignUploadApiFallbackFactory.class)
public interface FeignUploadApi {

    /**
     * 上传单个文件
     *
     * @param fileBase64
     *         文件base64字符串
     * @return 文件信息
     */
    @RequestMapping(value = "/single", method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    Result<FileInfo> base64Single(@RequestPart("fileBase64") String fileBase64);

    /**
     * 上传单个文件
     *
     * @param fileBase64
     *         文件base64字符串
     * @param path
     *         保存路径
     * @return 文件信息
     */
    @RequestMapping(value = "/single/{path}", method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    Result<FileInfo> base64Single(@RequestPart("fileBase64") String fileBase64, @PathVariable("path") String path);
}
